package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String key){
        return searchService.getSuggestions(key);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> searchAllByPage(@RequestBody RequestParams params) throws IOException {
        PageDTO<ItemDoc> result = searchService.searchAllByPage(params);
        return result;
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        Map<String, List<String>> result = searchService.getFilters(params);
        return result;
    }

}
